package it.openHWHackaton.arduinoTableSoccer;

import java.util.Iterator;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleToAction;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;


public class PlayerDX extends Actor{
	private Texture texture;
	private int h=(int) (Gdx.graphics.getHeight()/1.8);
	private boolean matchStarted=false;
	private BitmapFont scoreFont;
	private int currScore = 0;
	private String p1Name;
	private String p2Name;
	
	public PlayerDX(){
		texture = new Texture(Gdx.files.internal("data/playerDX.png"));
        setBounds(getX(),getY(),h*AspectRatio.getPlayerAspectRatio(),h);
        
        MoveToAction moveActionDX = new MoveToAction();
        moveActionDX.setPosition(Gdx.graphics.getWidth()/12*6, Gdx.graphics.getHeight()/4);
        moveActionDX.setDuration(3f);
        moveActionDX.setInterpolation(Interpolation.bounce);
        this.addAction(moveActionDX);
        
		scoreFont = new BitmapFont(Gdx.files.internal("data/Calibri-2.fnt"),
		         Gdx.files.internal("data/Calibri_0-2.png"), false);
		scoreFont.setColor(Color.BLACK);
    }

	@Override
	public void draw(SpriteBatch batch, float alpha){
	    batch.draw(texture,this.getX(),getY(),this.getOriginX(),this.getOriginY(),this.getWidth(),
	            this.getHeight(),this.getScaleX(), this.getScaleY(),this.getRotation(),0,0,
	            texture.getWidth(),texture.getHeight(),false,false);
	   // scoreFont.draw(batch, this.p1Name,Gdx.graphics.getWidth()/8, Gdx.graphics.getHeight()/4);
		//scoreFont.draw(batch, this.p2Name,Gdx.graphics.getWidth()/8, Gdx.graphics.getHeight()/6);

	    
	    scoreFont.draw(batch, ""+currScore, Gdx.graphics.getWidth()/10*3.9f +this.getWidth()/2, Gdx.graphics.getHeight()/4);

	}
	@Override
	public void act (float delta) {
		if(matchStarted){
			for(Iterator<Action> iter = this.getActions().iterator(); iter.hasNext();){
				iter.next().act(delta);
			}
		}
	}
	public void startMatch(){
		this.matchStarted=true;
	}
	public void reset(){
		this.currScore=0;
	}
	public void goal(){
		currScore++;
		SequenceAction sequenceAction = new SequenceAction();
		
		ScaleToAction scaleUP = new ScaleToAction();
		scaleUP.setScale(1.2f);
		scaleUP.setDuration(0.3f);
		
		ScaleToAction scaleDOWN = new ScaleToAction();
		scaleDOWN.setScale(1.0f);
		scaleDOWN.setDuration(0.3f);
		
		sequenceAction.addAction(scaleUP);
		sequenceAction.addAction(scaleDOWN);
		this.addAction(sequenceAction);
	}

	public String getP1Name() {
		return p1Name;
	}

	public void setP1Name(String p1Name) {
		this.p1Name = p1Name;
	}

	public String getP2Name() {
		return p2Name;
	}

	public void setP2Name(String p2Name) {
		this.p2Name = p2Name;
	}
	
	
	
	

}
